package com.wang.ymcc.mq;

import com.alibaba.fastjson.JSON;
import com.wang.lwm.constents.MQConstants;
import com.wang.lwm.dto.StationInMQDto;
import com.wang.lwm.result.JSONResult;
import com.wang.ymcc.service.IMessageSmsService;
import com.wang.ymcc.service.IMessageStationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@RocketMQMessageListener(topic = MQConstants.MQ_STATION_TOPIC,
        selectorExpression=MQConstants.MQ_STATION_TAGS	//tags
        ,consumerGroup = "service-course-consumer"
        ,messageModel = MessageModel.CLUSTERING)
@Slf4j
@Component
public class CourseMesage implements RocketMQListener<MessageExt> {

    @Autowired
    private IMessageStationService messageStationService;

    @Override
    public void onMessage(MessageExt messageExt) {
        //获取原始数据
        byte[] bytes = messageExt.getBody();
        //转换为字符串
        String s = new String(bytes);
        //转换为json对象
        StationInMQDto stationInMQDto = JSON.parseObject(s, StationInMQDto.class);
        //保存
        messageStationService.save(stationInMQDto);
    }
}
